package com.jimikongjian.service.dao.impl;

import com.jimikongjian.dao.IInterest;
import com.jimikongjian.models.Interest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fuxiuyang on 17/3/4.
 */
@Service("iInterestImpl")
public class IInterestImpl implements IInterest {

    @Autowired
//    @Qualifier("interestMapper")
    private IInterest iInterest;

    /**
     * 通过兴趣的某一确定的id号，获取某一确定的兴趣
     *
     * @param id
     * @return List<Interest>
     */
    public List<Interest> getInterestListById(int id) {
        if (id > 0){
            return iInterest.getInterestListById(id);
        }
        return null;
    }

    /**
     * 通过兴趣的某一确定的id号，获取某一确定的兴趣
     *
     * @param id
     * @return Interest
     */
    public Interest getInterestById(int id) {
        if (id > 0){
            List<Interest> interestList = getInterestListById(id);
            if (interestList.size() > 0){
                return interestList.get(0);
            }
        }
        return null;
    }

    /**
     * 通过用户的id号，获取用户兴趣标签id
     *
     * @param userId
     * @return List<Interest>
     */
    public List<Interest> getInterestListByUserId(int userId) {
        if (userId > 0){
            return iInterest.getInterestListByUserId(userId);
        }
        return null;
    }

    /**
     * 通过用户的id号，获取用户兴趣标签id
     *
     * @param tagId
     * @return List<Interest>
     */
    public List<Interest> getInterestListByTagId(int tagId) {
        if (tagId > 0){
            return iInterest.getInterestListByTagId(tagId);
        }
        return null;
    }

    /**
     * 插入一条新的兴趣
     *
     * @param interest
     */
    public void insertInterest(Interest interest) {
        if (interest.getUserId() > 0
                && interest.getTagId() > 0){
            iInterest.insertInterest(interest);
        }

    }

    /**
     * 更新一条新的兴趣
     *
     * @param interest
     */
    public void updateInterest(Interest interest) {
        if (interest.getUserId() > 0
                && interest.getTagId() > 0){
            iInterest.updateInterest(interest);
        }
    }

    /**
     * 删除一条新的兴趣
     *
     * @param interest
     */
    public void deleteInterest(Interest interest) {
        if (interest.getId() > 0){
            iInterest.deleteInterest(interest);
        }

    }
}
